﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Aop.Api.FileControllers
{
    /// <summary>
    /// 文件及文件夹操作类
    /// </summary>
    public class FileHelper
    {
        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="filePath">目录</param>
        /// <returns></returns>
        public string CreatFileOrdeflt(string filePath)
        {
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
                return "文件创建成功";
            }
            else
            {
                return "文件已存在";
            }
        }
        /// <summary>
        /// 移动文件
        /// </summary>
        /// <param name="oldfilePath">旧目录</param>
        /// <param name="newfilePath">新目录</param>
        /// <returns></returns>
        public string MoveFileOrdefilt(string oldfilePath,string newfilePath)
        {
            try
            {
                //File.Move(oldfilePath, newfilePath);
                FileInfo f1 = new FileInfo(oldfilePath);
                f1.CopyTo(newfilePath);
                f1.Delete();
                return "移动成功";
            }
            catch(IOException ioex)
            {
                return ioex.Message;
            }
            finally
            {

            }
        }
    }
}
